package com.usergood;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class UserGoodReducer extends Reducer<UserGoodBean, IntWritable, UserGoodBean, IntWritable> {
    private final IntWritable valueOutVisitSum = new IntWritable();

    /**
     * @param key     输入数据：U20230218183542473371    G20230303104950942338 ->1
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(UserGoodBean key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

        int nVisitSum = 0;
        for (IntWritable item : values) {
            nVisitSum += item.get();
        }
        valueOutVisitSum.set(nVisitSum);
        //key.setnVisitTime(nVisitSum);
        context.write(key, valueOutVisitSum);
    }
}
